<?php
/**************************** SERVICE INITIALIZATION BEGINS ****************************/
require_once("../../config.php");
require_once(ML_ROOT."/service-admin.php"); on_photos_edit();

$photo = isset($view_data[Protocol::PHOTO]) ? $view_data[Protocol::PHOTO] : NULL;
$model_list = isset($view_data[Protocol::MODEL_LIST]) ? $view_data[Protocol::MODEL_LIST] : NULL;
/***************************** SERVICE INITIALIZATION ENDS *****************************/
?>

<?php
/********************************* HTML CONTENT BEGINS *********************************/
require_once(ML_INCLUDE."/admin-header.php");
?>
	<h1>Photos Edit</h1>
	<form action="<?=url("/admin/photos-edit.php")?>" method="post" autocomplete="on" enctype="multipart/form-data">
	<table>
		<?php if (isset($photo[Protocol::ID])) :?>
		<tr>
			<td><label for="id">id</label></td>
			<td><input name="<?=Protocol::ID?>" id="id" type="id" value="<?=$photo[Protocol::ID]?>" readonly /></td>
		</tr>
		<?php endif ?>
		<tr>
			<td><label for="model_id">model_id</label></td>
			<td>
				<select name="<?=Protocol::MODEL_ID?>" id="model_id">
					<?php foreach ($model_list as $model) : ?>
					<?php if (isset($photo[Protocol::MODEL_ID]) && $photo[Protocol::MODEL_ID] == $model[Protocol::ID]) : ?>
					<option value="<?=$model[Protocol::ID]?>" selected="true">
					<?php else : ?>
					<option value="<?=$model[Protocol::ID]?>">
					<?php endif ?>
						<?=$model[Protocol::ID]." - ".$model[Protocol::NAME]?>
					</option>
					<?php endforeach ?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label for="file">file</label></td>
			<?php if (isset($photo[Protocol::THUMB_B])) :?>
			<td>
				<div>
					<a href="<?=media($photo[Protocol::FILE])?>" target="_blank">
						<img src="<?=media($photo[Protocol::THUMB_B])?>" />
					</a>
				</div>
				<div>
					<input name="<?=Protocol::FILE?>" id="file" type="file" accept="image/*" />
				</div>
			</td>
			<?php else :?>
			<td><input name="<?=Protocol::FILE?>" id="file" type="file" accept="image/*" /></td>
			<?php endif ?>
		</tr>
		<tr>
			<td><label for="description">description</label></td>
			<?php if (isset($model[Protocol::DESCRIPTION])) :?>
			<td>
				<input name="<?=Protocol::DESCRIPTION?>"
					id="description" type="text" value="<?=$model[Protocol::DESCRIPTION]?>" />
			</td>
			<?php else :?>
			<td><input name="<?=Protocol::DESCRIPTION?>" id="description" type="text" /></td>
			<?php endif ?>
		</tr>
		<tr>
			<td><label for="tags">tags</label></td>
			<?php if (isset($model[Protocol::TAGS])) :?>
			<td><input name="<?=Protocol::TAGS?>" id="tags" type="text" value="<?=$model[Protocol::TAGS]?>" /></td>
			<?php else :?>
			<td><input name="<?=Protocol::TAGS?>" id="tags" type="text" /></td>
			<?php endif ?>
		</tr>
		<?php if (isset($photo[Protocol::VIEWS])) :?>
		<tr>
			<td><label for="views">views</label></td>
			<td><input name="<?=Protocol::VIEWS?>" id="views" type="number" value="<?=$photo[Protocol::VIEWS]?>" /></td>
		</tr>
		<?php endif ?>
		<?php if (isset($photo[Protocol::LIKES])) :?>
		<tr>
			<td><label for="likes">likes</label></td>
			<td><input name="<?=Protocol::LIKES?>" id="likes" type="number" value="<?=$photo[Protocol::LIKES]?>" /></td>
		</tr>
		<?php endif ?>
		<tr>
			<td colspan="2"><button type="submit">Confirm</button></td>
		</tr>
	</table>
	</form>
<?php
require_once(ML_INCLUDE."/admin-footer.php");
/********************************** HTML CONTENT ENDS **********************************/
?>